package com.fowo.api.service.handleWork;

import com.amazon.spapi.client.ApiException;
import com.amazon.spapi.model.sellers.GetMarketplaceParticipationsResponse;
import com.amazon.spapi.model.sellers.MarketplaceParticipationList;
import com.fowo.api.syncAmazon.api.ListingService;
import com.fowo.api.syncAmazon.api.OrderService;
import com.fowo.api.syncAmazon.api.SellersService;
import com.fowo.api.syncAmazon.entity.TmpSellOrder;
import com.fowo.api.syncAmazon.service.impl.TmpSellOrderServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class AmazonService {

    @Resource
    private SellersService sellersService;
    @Resource
    private TmpSellOrderServiceImpl tmpSellOrderService;
    @Resource
    private OrderService orderUtil;
    @Resource
    private ListingService listingUtil;



    /**
     * 获取账号商城信息
     * @param refreshToken
     * @return
     * @throws ApiException
     */
    public MarketplaceParticipationList getMarketplaceParticipations(String refreshToken,String endpoint,String region) throws ApiException {
        GetMarketplaceParticipationsResponse getMarketplaceParticipationsResponse = sellersService.getMarketplaceParticipations(refreshToken,endpoint,region);
        return getMarketplaceParticipationsResponse.getPayload();
    }

    /**
     * 获取订单
     * @throws ApiException
     */
    public void getOrder() throws Exception {
        List<TmpSellOrder> temSellOrderList = orderUtil.getOrder();
        tmpSellOrderService.saveBatch(temSellOrderList);
//        tmpSellOrderService.save(temSellOrderList);
    }



    /**
     * 获取Listing
     * @throws Exception
     */
    public void getListing() throws Exception {
        listingUtil.getListing();
    }

}
